package com.example.isoftservice.service.impl;

import  com.example.isoftservice.mapper.StockMapper;
import com.example.isoftservice.pojos.Stock;

import com.example.isoftservice.service.StockService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StockServiceImpl implements StockService {
    @Resource
    private  StockMapper stockMapper;
    @Override
    @Cacheable(cacheNames ="address",key="#addressId")
    public Map<String, Object> selectSubmit(Stock stock) {
        Map<String, Object> map = new HashMap<>();
        System.out.println(stock);
       // PageHelper.startPage(stock.getPage(),stock.getRows());
        List<Map<String,Object>> list = stockMapper.selectSubmit(stock);
        List<Map<String,Object>> count=stockMapper.selectSubmitNumber(stock);
        System.out.println(count);

        PageInfo<Map<String,Object>> pageInfo=new PageInfo<>(list);
        PageInfo<Map<String,Object>> pageInfoNumber=new PageInfo<>(count);
        map.put("count",pageInfoNumber.getTotal());
        map.put("data",pageInfo.getList());



        return map;


    }

    @Override
    public Map<String, Object> selectPass(Stock stock) {
        Map<String, Object> map = new HashMap<>();
        System.out.println("aaaaaaaaaaaaaaa"+stock);
        //PageHelper.startPage(stock.getPage(),stock.getRows());
        List<Map<String,Object>> list = stockMapper.selectPass(stock);
        List<Map<String,Object>> count = stockMapper.selectPassNumber(stock);

        PageInfo<Map<String,Object>> pageInfo=new PageInfo<>(list);
        PageInfo<Map<String,Object>> pageInfoNumber=new PageInfo<>(count);
        map.put("count",pageInfoNumber.getTotal());
        map.put("data",pageInfo.getList());



        return map;
    }
    public Map<String, Object> selectNoPass(Stock stock) {
        Map<String, Object> map = new HashMap<>();
        System.out.println(stock);
        //PageHelper.startPage(stock.getPage(),stock.getRows());
        List<Map<String,Object>> list = stockMapper.selectNoPass(stock);
        List<Map<String,Object>> count = stockMapper.selectNoPassNumber(stock);
        PageInfo<Map<String,Object>> pageInfo=new PageInfo<>(list);
        PageInfo<Map<String,Object>> pageInfoNumber=new PageInfo<>(count);
        map.put("count",pageInfoNumber.getTotal());
        map.put("data",pageInfo.getList());



        return map;
    }

    @Override
    public Map<String, Object> selectAdress() {
        Map<String, Object> map = new HashMap<>();

        List<Map<String,Object>> list = stockMapper.selectAddress();
        map.put("data",list);

    return  map;}

    @Override
    public Map<String, Object> selectDealer() {
        Map<String, Object> map = new HashMap<>();

        List<Map<String,Object>> list = stockMapper.selectDealer();
        map.put("data",list);
        return map;
    }

    @Override
    public Map<String, Object> selectProduct() {
        Map<String, Object> map = new HashMap<>();

        List<Map<String,Object>> list = stockMapper.selectProduct();
        map.put("data",list);
        return map;
    }

    @Override
    public Map<String, Object> stockInsert(Stock stock) {
        Map<String,Object>  map=new HashMap<>();
        int count = stockMapper.stockInsert(stock);
        if (count>=1){

            map.put("flag",true);
        }
        if (count<1){
            map.put("flag",false);
        }
        return  map;
    }

    public Map<String, Object> stockDelete(Stock stock) {
        Map<String,Object>  map=new HashMap<>();
        int count = stockMapper.stockDelete(stock);
        if (count>=1){

            map.put("flag",true);
        }
        if (count<1){
            map.put("flag",false);
        }
        return  map;
    }
    @Override
    public Map<String, Object> stockUpdate(Stock stock) {
        Map<String,Object> map=new HashMap<>();
        Integer count=this.stockMapper.stockUpdate(stock);
        if (count >=1) {
            map.put("flag",true);
            map.put("code",0);
            map.put("massage","更新成功");
        }else {
            map.put("flag",false);
            map.put("code",1);
            map.put("massage","更新失败");
        }
        return map;
    }
    @Override
    public Map<String, Object> selectStatus(Stock stock) {
        Map<String,Object> map=new HashMap<>();
        List<Map<String,Object>> list =this.stockMapper.selectstatus(stock);
        map.put("list",list);
        return map;
    }
}
